package wcu;

import java.io.BufferedOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;

public class MettlerScaleCommands {
	
	private Socket sock;
//	TAKEN FROM THE REFERENCE MANUAL FOR THE METTLER TOLEDO REMOTE
//	INPUT TYPES SUPPORTED
//	x1=1 Real (positive values only) 
//			 x1=2 Real 
//			 x1=3 Integer (positive values only) 
//			 x1=4 Integer 
//			 x1=5 EU date (DD.MM.YYYY) 
//			 x1=6 US date (MM/DD/YYYY) 
//			 x1=7 Time (HH:MM:SS) 
//			 x1=8 Alphanumeric 
//			 x1=9 Password (input visible) 
//			 x1=10 Password (input displayed as ***) 
//			 x1=11 Alphanumeric Password 
//			 (input displayed as ***)
	
	public void sendRM20(String inputType, String instruction, String mode) {
		try {
			OutputStream oS = sock.getOutputStream();
			BufferedOutputStream bOS = new BufferedOutputStream(oS);
			DataOutputStream dOS = new DataOutputStream(bOS);

			dOS.writeBytes("RM20 " + inputType + " " + "\"" + instruction + "\"" + " " + "\"\"" + " " + "\"" + mode + "\"" + "\r\n");
			dOS.flush();
			
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void sendTara(){
		try {
			OutputStream oS = sock.getOutputStream();
			BufferedOutputStream bOS = new BufferedOutputStream(oS);
			DataOutputStream dOS = new DataOutputStream(bOS);

			dOS.writeBytes("T" + "\r\n");
			dOS.flush();
			
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void SendWeigh(){
		try {
			OutputStream oS = sock.getOutputStream();
			BufferedOutputStream bOS = new BufferedOutputStream(oS);
			DataOutputStream dOS = new DataOutputStream(bOS);

			dOS.writeBytes("S" + "\r\n");
			dOS.flush();
			
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void sendDeleteDisplay(){
		try {
			OutputStream oS = sock.getOutputStream();
			BufferedOutputStream bOS = new BufferedOutputStream(oS);
			DataOutputStream dOS = new DataOutputStream(bOS);

			dOS.writeBytes("DW" + "\r\n");
			dOS.flush();
			
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void sendWriteInDisplay(String message){
		try {
			OutputStream oS = sock.getOutputStream();
			BufferedOutputStream bOS = new BufferedOutputStream(oS);
			DataOutputStream dOS = new DataOutputStream(bOS);

			dOS.writeBytes("D" + " " + "\"" + message + "\"" + "\r\n");
			dOS.flush();
			
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void sendWriteInSecDisplay(String message){
		try {
			OutputStream oS = sock.getOutputStream();
			BufferedOutputStream bOS = new BufferedOutputStream(oS);
			DataOutputStream dOS = new DataOutputStream(bOS);

			dOS.writeBytes("P111" + " " + "\"" + message + "\"" + "\r\n");
			dOS.flush();
			
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void setSocket(Socket sock){
		this.sock = sock;
	}
}
